package cn.italkcloud.cph.constants.enums;

import cn.italkcloud.cph.helper.AuthHelper;
import cn.italkcloud.cph.utils.StringUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dominate
 * @since 2023/5/8
 */
@Getter
public enum PermDataEnum {

    NO_PREM("0", "无权限", ""),

    RECHARGE_ALL("1-1", "可充值全部账号", "/recharge/all", "recharge", 1),
    RECHARGE("1-2", "可充值，仅限自己账号", "/recharge/base", "recharge", 0),

    BIND_CUSTOMER("2-1", "可进行绑定VOS账户", "/bind/vos-customer"),
    MODIFY_CUSTOMER("2-2", "可修改VOS账户信息", "/modify/vos-customer"),
    SHOW_ALL_CUSTOMER("2-3", "查看所有VOS账户", "/query/vos-customer/all"),

    MODIFY_VOS_SERVER("3-1", "可修改VOS服务器信息", "/modify/vos-server"),
    SHOW_ALL_VOS_SERVER("3-2", "可查看所有VOS服务器", "/query/vos-server/all"),
    ;

    private final String id;
    private final String desr;
    private final String path;
    private final String sign;
    private final int signLevel;

    PermDataEnum(String id, String desr, String path) {
        this(id, desr, path, StringUtil.EMPTY, 0);
    }

    PermDataEnum(String id, String desr, String path, String sign, int signLevel) {
        this.path = path;
        this.id = id;
        this.desr = desr;
        this.sign = sign;
        this.signLevel = signLevel;
    }

    public static List<String> getIds() {
        List<String> ids = new ArrayList<>();
        for (PermDataEnum value : values()) {
            ids.add(value.getId());
        }
        return ids;
    }

    public static Map<String, String> getPathMap() {
        Map<String, String> pathMap = new HashMap<>();
        for (PermDataEnum value : values()) {
            pathMap.put(value.getId(), value.getPath());
        }
        return pathMap;
    }

    public boolean verify(String token) {
        return AuthHelper.verify(token, this.getId());
    }

}
